#include <iostream>
#include <memory>
#include "client.hpp"
#include "err.hpp"

void Usage()
{
    std::cout << "Please enter the correct format: "
              << "./client [server's ip] [server's port]" << std::endl;
}

// ./client [ip] [port] (由用户指定服务器的ip和port)
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        Usage();
        exit(USAGE_ERR);
    }

    std::unique_ptr<UdpClient> uc_ptr(new UdpClient(argv[1], atoi(argv[2])));
    uc_ptr->Initial();

    while (true)
    {
        std::cout << "ENTER:> ";
        std::string msg;
        std::getline(std::cin, msg);
        // 用户不断发送消息并接收从服务器返回的数据
        uc_ptr->Send(msg);
        uc_ptr->Recv();
    }

    return 0;
}